package com.zry.pda.utils

import android.annotation.SuppressLint
import java.lang.Long
import java.text.SimpleDateFormat
import java.util.*


/**
 * Created by 19428 on 2017/5/19.
 */


class DateTimeUtilsKt {
    @SuppressLint("SimpleDateFormat")
    fun getNowDateTime(State: String): String {
        val now = Date()
        val dateFormat = SimpleDateFormat(State)// 可以方便地修改日期格式
        return dateFormat.format(now)
    }


    @SuppressLint("SimpleDateFormat")
    fun getBeiJingTime(seconds: String?, format: String?): String {
        var format = format
        if (seconds == null || seconds.isEmpty() || seconds == "null") {
            return ""
        }
        if (format == null || format.isEmpty()) {
            format = "yyyyMMddHHmmss"
        }
        val sdf = SimpleDateFormat(format)
        return sdf.format(Date(Long.valueOf(seconds + "000")!!))
    }

    @SuppressLint("SimpleDateFormat")
    //获取昨天的时间
    fun getYesterDay(State: String): String {
        val cal = Calendar.getInstance()
        cal.add(Calendar.DATE, -1)
        val time = cal.time
        return SimpleDateFormat(State).format(time)

    }
    //将年月日转换成我们自己需要的格式

    fun getUserData(userData: String): String {
        return userData.substring(0, 4) + "年" + userData.substring(4, 6) + "月" + userData.substring(6, 8) + "日"
    }

    fun getUserDataTime(userData: String): String {
        return userData.substring(0, 4) + "-" + userData.substring(4, 6) + "-" + userData.substring(6, 8) + " " + userData.substring(8, 10) + "-" + userData.substring(10, 12) + "-" + userData.substring(12, 14)
    }

    //将当前的日期先转换为年月日格式
    fun getUserNowData(userData: String): String {
        val month = Integer.parseInt(userData.substring(4, 6)).toString()
        val day = Integer.parseInt(userData.substring(6, 8)).toString()
        return userData.substring(0, 4) + "年" + month + "月" + day + "日"
    }


//        //获取农历日期
//        fun  getLunarDate(String gregorianDate):String {
//            //获取当前的农历日期
//            int[] lunarDate = LunarCalendar.solarToLunar(Integer.parseInt(gregorianDate.substring(0, 4)), Integer.parseInt(gregorianDate.substring(4, 6)),
//                    Integer.parseInt(gregorianDate.substring(6, 8)));
//            return "(" + UppercaseUtil.UppercaseData(lunarDate[1] + "", lunarDate[2] + "") + ")";
//        }


    @SuppressLint("SimpleDateFormat")
    fun getConversionTime(beginDate: String, State: String): String {
        val sdf = SimpleDateFormat(State)
        return sdf.format(Date(Long.parseLong(beginDate)))
    }

}
